package com.soft.base.util;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.concurrent.TimeUnit;
/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class GuavaCacheUtil {

    private static Cache<String, Object> cache;
    private static Cache<String, Object> cacheBuilder() {
        Cache<String, Object> cache = CacheBuilder.newBuilder()
                .maximumSize(100)
                .expireAfterAccess(60, TimeUnit.MINUTES)
                .concurrencyLevel(Runtime.getRuntime().availableProcessors())
                .recordStats()
                .build();
        return cache;
    }

    public static Cache<String, Object> getCache() {
        if (cache == null) {
            synchronized (GuavaCacheUtil.class) {
                cache = cacheBuilder();
            }
        }
        return cache;
    }
}
